// pages/admin/admin.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },
  /**
   * 组件的初始数据
   */
  data: {
    list:[],
    height:800,
  },
  lifetimes: {
    attached: function () {
      //hgz/demand/queryListWithPage
      var tabHeight = ((44 + app.globalData.systemInfo.statusBarHeight) * (750 / app.globalData.systemInfo.windowWidth)); //将高度乘以换算后的该设备的rpx与px的比例
      var windowHeight = app.globalData.windowHeight - 120 - tabHeight;
        this.setData({
          height: windowHeight
       })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    onShow: function () {
      var params = {
        pageNum:1,
        pageSize:1000
      }
      app.request.postHeadForm('hgz/demand/queryListWithPage', params)
      .then(res =>{
          var dataList = res.data.list;
          for(var i=0;i<dataList.length;i++){
            var masterialList = dataList[i].material.split(',');
            var modelList = dataList[i].model.split(',');
            var weightList = dataList[i].weight.split(',');
            var childList = [];
            for(var j=0;j<masterialList.length;j++){
              var maters = masterialList[j];
              var  models = "";
              var  weighs = "";
              if(j<modelList.length){
                models = modelList[j];
              }  
              if(j<weightList.length){
                weighs = weightList[j];
              }  
              childList.push({
                mater:maters,
                model:models,
                weigh:weighs
              })
            }
            dataList[i].childList = childList;
            var imgList2 = dataList[i].imgPath.split(';');
            var imgList = [];
            for(var j=0;j<imgList2.length;j++){
              if(imgList2[j]!=null&&imgList2[j].length>5){
                imgList.push(imgList2[j])  
              }
            }
            dataList[i].banner = imgList;
          }
          this.setData({
            list:dataList
          })
      })
    },
    detail(e){
      var id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/pages/demanddetail/demand?id=' + id,
      })
    },
    showImageBanner(e){
        var itemIndex = e.currentTarget.dataset.id;
        var banner = e.currentTarget.dataset.val;
        wx.previewImage({
          current: banner[itemIndex], // 当前显示图片的http链接
          urls: banner // 需要预览的图片http链接列表
        })
    }
  }

})
